var gulp = require('gulp')
var less = require('gulp-less')
var plumber  = require('gulp-plumber')
var path = require('path')
var browserSync = require('browser-sync').create()
var reload = browserSync.reload

// 静态服务器
gulp.task('serve', ['less'], function() {
  browserSync.init({
    server: '.',
    index: 'html/home.html'
  })

  gulp.watch('less/*.less', ['less'])
  gulp.watch('**/*.html').on('change', reload)
  gulp.watch('js/*.js').on('change', reload)
})

gulp.task('less', function() {
  return gulp.src('./less/*.less')
    .pipe(plumber())
    .pipe(less())
    .pipe(gulp.dest('./css'))
    .pipe(reload({stream: true}))
})

gulp.task('default', ['serve']);
